package data_structures_and_algorithms.tree;

import common.TreeNode;

/**
 * @ClassName Code_0100_isSameTree
 * @Description:
 * @Author: yongliang.ma
 * @Create_time:2022/10/26 20:52
 */
public class Code_0100_isSameTree {

    public boolean isSameTree(TreeNode p, TreeNode q) {
        if (p == null && q ==null)
            return true;
        // 这个 学习一下，p、q中有一个满足等于null
        if (p == null ^ q == null)
            return false;

        if (q.val != p.val)
            return false;

        // 此时p q均不为null
        return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
    }
}
